package com.liutaw.nanjingair.views.activities.products;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ScrollView;
import android.widget.TextView;

import com.liutaw.nanjingair.R;
import com.liutaw.nanjingair.presenter.products.WeatherPresenter;
import com.liutaw.nanjingair.views.activities.base.BaseActivity;
import com.liutaw.nanjingair.views.adapter.WeatherPerHourInfoAdapter;
import com.liutaw.nanjingair.views.adapter.WeatherPerSixInfoAdapter;
import com.liutaw.nanjingair.views.viewcomponent.DividerLine;
import com.liutaw.nanjingair.views.viewcomponent.WrappingLinearLayoutManager;
import com.liutaw.nanjingair.views.viewcomponent.weather.WeatherReport;
import com.liutaw.navigationbarlib.NaviBarBuilder;
import com.szjlxh.data.entity.WeatherPerSixHourBean;
import com.szjlxh.data.entity.WeatherSevenDayBean;
import com.szjlxh.data.entity.WeatherThreeDayForcastBean;
import com.szjlxh.domain.model.WeatherPerHour;
import com.szjlxh.domain.model.index.WeatherSevenDay;

import java.util.List;

import javax.inject.Inject;

import butterknife.Bind;
import butterknife.ButterKnife;

public class WeatherForcastActiviy extends BaseActivity implements IWeatherForcastView {
    @Bind(R.id.text_current_location)
    TextView textCurrentLocation;
    @Bind(R.id.text_detail_before)
    TextView textDetailBefore;
    @Bind(R.id.recycleview_perhour)
    RecyclerView recycleviewPerhour;
    @Bind(R.id.recycleview_perthreehour)
    RecyclerView recycleviewPerthreehour;
//    @Bind(R.id.recycleview_sinxhours)
//    RecyclerView recycleviewSinxhours;
    @Bind(R.id.weather_report)
    WeatherReport weatherReport;
    @Bind(R.id.text_threeday_short_forcast)
    TextView textThreedayShortForcast;
    @Bind(R.id.scrollView)
    ScrollView scrollView;

    @Inject
    WeatherPresenter weatherPresenter;

    private WeatherPerHourInfoAdapter weatherPerHourInfoAdapter;

    public static Intent getCallingIntent(Context context) {
        return new Intent(context, WeatherForcastActiviy.class);
    }

//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.layout_weather_forcast_activiy);
//    }

    @Override
    protected int getLayoutResId() {
        return R.layout.layout_weather_forcast_activiy;
    }

    @Override
    protected void initNaviBar(NaviBarBuilder naviBarBuilder) {
        //蓝色主题标题栏
//        naviBarBuilder.getWholeView().setBackgroundColor(Color.parseColor("#D9395EAB"));
        naviBarBuilder.getWholeView().setBackgroundColor(getResources().getColor(R.color.title_bar_bg));
        naviBarBuilder.buildCenterView().buildTitleText("天气预报",true);
    }

    @Override
    protected String getCusTitle() {
        return "天气预报";
    }

    @Override
    protected void initOnCreate() {
        initRecyclerView(recycleviewPerhour);
        initRecyclerView(recycleviewPerthreehour);
//        initRecyclerView(recycleviewSinxhours);

//        ActivityComponent component = DaggerActivityComponent.builder().applicationComponent(getApplicationComponent()).activityModule(getActivityModule()).build();
//        component.inject(this);
        weatherPresenter = new WeatherPresenter();
        weatherPresenter.setiWeatherForcastView(this);
        weatherPresenter.requestLocation();
        weatherPresenter.requestPerHour();
        weatherPresenter.reqeustPerThress();
//        weatherPresenter.requestPerSix();
        weatherPresenter.requestSevenDay();
        weatherPresenter.requestThreeDayForcast();
    }

    @Override
    protected void initCusView(View view) {
        ButterKnife.bind(this, view);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }

    @Override
    public void onPerHourLoaded(List<WeatherPerHour> data) {
        recycleviewPerhour.setAdapter(new WeatherPerHourInfoAdapter(this,data));
    }

    @Override
    public void onPerThreeLoaded(List<WeatherPerHour> data) {
        recycleviewPerthreehour.setAdapter(new WeatherPerHourInfoAdapter(this,data));
    }

    @Override
    public void onPerSixLoaded(List<WeatherPerSixHourBean> data) {
//        recycleviewSinxhours.setAdapter(new WeatherPerSixInfoAdapter(this,data));
    }

    @Override
    public void onSevenDayLoaded(List<WeatherSevenDay> weatherSevenDayBean) {
        weatherReport.setWeatherDayInfos(weatherSevenDayBean);
    }

    @Override
    public void onThreeDayForcastLoaded(WeatherThreeDayForcastBean bean) {
        textThreedayShortForcast.setText(bean.getResult().getVC_FORCONTENT());
    }


    private void initRecyclerView(RecyclerView recyclerView) {
        LinearLayoutManager linearLayoutManager = new WrappingLinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        DividerLine dividerLine = new DividerLine(DividerLine.HORIZONTAL);
        dividerLine.setSize(1);
        dividerLine.setColor(0x33FFFFFF);
        recyclerView.addItemDecoration(dividerLine);
    }
}
